Hi @dublove , I get your error if the font is missing, also any fonts activated from Adobe Fonts do not have an accessible location, so they will not copy.
You could catch a missing font and display an alert, but this would not handle Adobe Type fonts, which can not be packaged or copied:
//获取当前文档(Get the current document)
var doc = app.activeDocument;
//获取字体列表(Get the list of fonts)
var fonts = doc.fonts.everyItem().name;
//创建数组(Creating Arrays)
var fontFiles = [];
//循环字体并添加到数组中(Loop through the fonts and add to the array)
for (var i = 0; i < fonts.length; i++) {
var font = fonts[i];
try {
var fontFile = File(doc.fonts.itemByName(font).location);
if (arrayContains(fontFiles, fontFile) == false) {
fontFiles.push(fontFile);
}
}catch(e) {
alert("The Font " + doc.fonts.itemByName(font).name +" is not available")
}
}
//创建打包文件夹(Creating a Packaging Folder)
var packageFolder = Folder(doc.filePath + "/Package");
if (!packageFolder.exists) {
packageFolder.create();
}
//将字体复制到打包文件夹(Copy the fonts to the packaging folder)
for (var i = 0; i < fontFiles.length; i++) {
var fontFile = fontFiles[i];
var newFile = File(packageFolder.fsName + "/" + fontFile.name);
fontFile.copy(newFile);
}
//打开打包文件夹(Open the packing folder)
packageFolder.execute();
function arrayContains(arr, item) {
for (var i = 0; i < arr.length; i++) {
if (arr[i].toString() == item.toString()) {
return true;
}
}
return false;
}
... View more